/*
ID: huangmingbo
LANG: JAVA
TASK: gift1
*/
import java.io.*;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.StringTokenizer;

public class gift1 {

    public static void main(String[] args) throws IOException {
        // read file
        InputStreamReader inputStreamReader = new InputStreamReader(gift1.class.getResourceAsStream("gift1.in"));
        BufferedReader input = new BufferedReader(inputStreamReader);
        // outputfile
        PrintWriter out = new PrintWriter(new FileWriter("gift1.out"));

        // read group
        int groupNum = Integer.parseInt(input.readLine());

        // read person
        String name;
        Map<String, Integer> map = new LinkedHashMap<>((int)(groupNum/0.75) + 1);
        for (int i = 0; i < groupNum; i++) {
            map.put(input.readLine(), 0);
        }

        String giverName;
        StringTokenizer stringTokenizer;
        while (null != (giverName = input.readLine())) {
            // read amount and give number
            stringTokenizer = new StringTokenizer(input.readLine());
            // amount
            int amount = Integer.parseInt(stringTokenizer.nextToken());
            // given number
            int givenNumber = Integer.parseInt(stringTokenizer.nextToken());
            // amount per  persion
            int amountPerPerson = givenNumber > 0 ? amount / givenNumber : 0;

            // read given person
            for (int i = 0; i < givenNumber; i++) {
                String givenName = input.readLine();
                // increase the money
                if (amountPerPerson > 0) {
                    map.put(givenName, map.get(givenName) + amountPerPerson);
                }
            }



            // decrease the money
            if (amount > 0 && givenNumber > 0) {
                map.put(giverName, map.get(giverName) - (amountPerPerson * givenNumber));
            }

        }

        map.forEach((k, v)->{
            out.println(k + " " + v);
        });
        out.close();

    }


}
